package com.gitee.minimalismstyle.fresh.common.data.beetl.extra

import com.gitee.minimalismstyle.fresh.common.core.domain.SnowflakeIdWorker
import org.beetl.sql.core.IDAutoGen
import org.beetl.sql.ext.SnowflakeIDWorker
import org.springframework.stereotype.Component


/**
 * 一个简单雪花算法示例，注意，不要用它在集群环境，因为他的workId和datacenterId都是0
 * ，不具备分布式唯一性
 * <pre>{code
 * @AssingId("simple")
 * Long id;
 * }</pre>
 *
 * 必须调用[org.beetl.sql.core.SQLManager.addIdAutoGen] 来使用
 * @see org.beetl.sql.annotation.entity.AssignID
 *
 * @author xiandafu
 */
@Component
class SnowflakeIDAutoGen(val snowflakeIdWorker: SnowflakeIdWorker) : IDAutoGen<Long> {

    override fun nextID(params: String): Long {
        return snowflakeIdWorker.nextId()
    }
}
